package com.example.bootrocketmq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

/**
 * @Date 2021/9/7
 **/
@Component
public class Consumer {

    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 使用@StreamListener来监听消息
     */
    @StreamListener(value = CustomerChannel.INPUT)
    public void testNormalListener(Message message) {
        logger.info("正常消息, 无header, 无tag, " + message.getHeaders().get("TAGS") + " " + message.getPayload().toString());
    }

    /**
     * 使用@StreamListener来监听消息
     */
    @StreamListener(value = CustomerChannel.INPUT, condition = "headers['version']=='1.0'")
    public void testCustomListener(Message message) {
        logger.info("version=1.0, " + message.getHeaders().get("TAGS") + " " + message.getPayload().toString());
    }

    /**
     * 使用@StreamListener来监听消息
     */
    @StreamListener(value = CustomerChannel.INPUT, condition = "headers['version']=='2.0'")
    public void testCustomListenerFilter(Message message) {
        logger.info("version=2.0, " + message.getHeaders().get("TAGS") + " " + message.getPayload().toString());
    }
}
